package com.template.templateuser.domain.mapper;

import com.template.templateuser.domain.dto.SysMenuDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface SysMenuMapper {


    @Select({
            "<script>",
            "SELECT * from sys_menu  where deleted=0",
            "</script>",
    })
    List<SysMenuDTO> getSysMenuAllList();



    @Select({
            "<script>",
            "SELECT * from sys_menu  where parentId=#{parentId}  and deleted=0",
            "</script>",
    })
    List<SysMenuDTO> getSysMenuListByParentId(@Param("parentId") Long parentId);


    /**
     * 通过id获取菜单信息
     *
     * @param id
     * @return
     */
    @Select({
            "<script>",
            "select * from sys_menu where deleted=0 and id=#{id}",
            "</script>",
    })
    SysMenuDTO findSysMenuById(@Param("id") Long id);


    /**
     * 保存
     * @param sysMenuDTO
     * @return
     */
    @Insert({
            "<script>",
            "INSERT INTO sys_menu",
            "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\" >",
            "   <if test=\"parentId != null\" >",
            "       parent_id,",
            "   </if>",
            "   <if test=\"menuName != null\" >",
            "       menu_name,",
            "   </if>",
            "   <if test=\"orderNum != null\" >",
            "       order_num,",
            "   </if>",
            "   <if test=\"url != null\" >",
            "       url,",
            "   </if>",
            "   <if test=\"target != null\" >",
            "       target,",
            "   </if>",
            "   <if test=\"menuType != null\" >",
            "       menu_type,",
            "   </if>",
            "   <if test=\"visible != null\" >",
            "       visible,",
            "   </if>",
            "   <if test=\"deleted != null\" >",
            "       deleted,",
            "   </if>",
            "   <if test=\"perms != null\" >",
            "       perms,",
            "   </if>",
            "   <if test=\"icon != null\" >",
            "       icon,",
            "   </if>",
            "   <if test=\"createTime != null\" >",
            "       create_time,",
            "   </if>",
            "   <if test=\"remark != null\" >",
            "       remark,",
            "   </if>",
            "   <if test=\"updateTime != null\" >",
            "       update_time,",
            "   </if>",
            "   <if test=\"menuKey != null\" >",
            "       menu_key,",
            "   </if>",
            "</trim>",
            "<trim prefix=\"values (\" suffix=\")\" suffixOverrides=\",\" >",
            "   <if test=\"parentId != null\" >",
            "       #{parentId},",
            "   </if>",
            "   <if test=\"menuName != null\" >",
            "       #{menuName},",
            "   </if>",
            "   <if test=\"orderNum != null\" >",
            "       #{orderNum},",
            "   </if>",
            "   <if test=\"url != null\" >",
            "       #{url},",
            "   </if>",
            "   <if test=\"target != null\" >",
            "       #{target},",
            "   </if>",
            "   <if test=\"menuType != null\" >",
            "       #{menuType},",
            "   </if>",
            "   <if test=\"visible != null\" >",
            "       #{visible},",
            "   </if>",
            "   <if test=\"deleted != null\" >",
            "       #{deleted},",
            "   </if>",
            "   <if test=\"perms != null\" >",
            "       #{perms},",
            "   </if>",
            "   <if test=\"icon != null\" >",
            "       #{icon},",
            "   </if>",
            "   <if test=\"createTime != null\" >",
            "       #{createTime},",
            "   </if>",
            "   <if test=\"remark != null\" >",
            "       #{remark},",
            "   </if>",
            "   <if test=\"updateTime != null\" >",
            "       #{updateTime},",
            "   </if>",
            "   <if test=\"menuKey != null\" >",
            "       menuKey,",
            "   </if>",
            "</trim>",
            "</script>",
    })
    @SelectKey(resultType = long.class, keyColumn = "id", before = false, statement = "SELECT LAST_INSERT_ID() AS id",
            keyProperty = "id")
    int save(SysMenuDTO sysMenuDTO);

    /**
     * 更新
     *
     * @param sysMenuDTO
     * @return java.lang.Integer
     *
     */
    @Update({
            "<script>",
            "update `sys_menu` ",
            "<set > ",
            "  <if test=\"parentId != null\" > ",
            "    parent_id = #{parentId}, ",
            "  </if> ",
            "  <if test=\"menuName != null\" > ",
            "    menu_name = #{menuName}, ",
            "  </if> ",
            "  <if test=\"orderNum != null\" > ",
            "    order_num = #{orderNum}, ",
            "  </if> ",
            "  <if test=\"url != null\" > ",
            "    url = #{url}, ",
            "  </if> ",
            "  <if test=\"target != null\" > ",
            "    target = #{target}, ",
            "  </if> ",
            "  <if test=\"menuType != null\" > ",
            "    menu_type = #{menuType}, ",
            "  </if> ",
            "  <if test=\"icon != null\" > ",
            "    icon = #{icon}, ",
            "  </if> ",
            "  <if test=\"deleted != null\" > ",
            "    deleted = #{deleted}, ",
            "  </if> ",
            "  <if test=\"perms != null\" > ",
            "    perms = #{perms}, ",
            "  </if> ",
            "  <if test=\"visible != null\" > ",
            "    visible = #{visible}, ",
            "  </if> ",
            "  <if test=\"remark != null\" > ",
            "    remark = #{remark}, ",
            "  </if> ",
            "  <if test=\"updateTime != null\" > ",
            "    update_time = #{updateTime}, ",
            "  </if> ",
            "   <if test=\"menuKey != null\" >",
            "       menu_key= #{menuKey}, ",
            "   </if>",
            "</set> ",
            "   where id = #{id}",
            "</script>",
    })
    Integer updateById(SysMenuDTO sysMenuDTO);





}
